package cn.wolfcode.luowowo.wensite.web.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.domain.StrategyDetail;
import cn.wolfcode.luowowo.article.domain.Travel;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo.article.service.ITravelCommendService;
import cn.wolfcode.luowowo.article.service.ITravelService;
import cn.wolfcode.luowowo.comment.domain.StrategyComment;
import cn.wolfcode.luowowo.comment.service.IStrategyCommentService;
import cn.wolfcode.luowowo.member.service.IUserInfoService;
import cn.wolfcode.luowowo.search.domain.DestinationTemplate;
import cn.wolfcode.luowowo.search.domain.TravelTemplate;
import cn.wolfcode.luowowo.search.service.IDestinationTemplateSearchService;
import cn.wolfcode.luowowo.search.service.IStrategyTemplateSearchService;
import cn.wolfcode.luowowo.search.service.ITravelTemplateSearchService;
import cn.wolfcode.luowowo.search.service.IUserInfoTemplateSearchService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.hibernate.validator.constraints.pl.REGON;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class DataController {

    @Reference
    private IStrategyCommentService strategyCommentService;

    @Reference
    private IUserInfoTemplateSearchService userInfoTemplateSearchService;
    @Reference
    private IStrategyTemplateSearchService strategyTemplateSearchService;

    @Reference
    private IStrategyDetailService strategyDetailService;

    @Reference
    private IDestinationService destinationService;

    @Reference
    private ITravelService travelService;

    @Reference
    private IUserInfoService userInfoService;

    @Reference
    private ITravelCommendService travelCommendService;

    @Reference
    private IDestinationTemplateSearchService templateSearchService;

    @Reference
    private IDestinationTemplateSearchService destinationTemplateSearchService;


    @Reference
    private ITravelTemplateSearchService travelTemplateSearchService;


    @RequestMapping("/addMongoDB")
    @ResponseBody

    public String add() {

        StrategyComment comment = new StrategyComment();
        comment.setContent("初始化....");

        strategyCommentService.save(comment);

        return "ok";
    }


    @RequestMapping("/dataInit")
    @ResponseBody
    public String dataInit() {

//        //用户初始化--------------------------
//        List<UserInfo> us = userInfoService.list();
//        for (UserInfo u : us) {
//            UserInfoTemplate tt = new UserInfoTemplate();
//            tt.setId(u.getId());
//            tt.setDestName(u.getCity());
//            tt.setFansnum(11);
//            tt.setHeadUrl(u.getHeadImgUrl());
//            tt.setInfo(u.getInfo());
//            tt.setLevel(u.getLevel());
//            tt.setNickname(u.getNickname());
//            tt.setReplynum(10);
//            tt.setTravelnum(2);
//            userInfoTemplateSearchService.saveOrUpdate(tt);
//        }

        //攻略初始化
//        StrategyTemplate t = null;
//        List<StrategyDetail> all = strategyDetailService.list();
//        for (StrategyDetail detail : all) {
//            t = new StrategyTemplate();
//            t.setId(detail.getId());
//            t.setTitle(detail.getTitle());
//            t.setSubTitle(detail.getSubTitle());
//            t.setDestId(detail.getDest().getId());
//            t.setDestName(detail.getDest().getName());
//            t.setThemeId(detail.getTheme().getId());
//            t.setThemeName(detail.getTheme().getName());
//            t.setSummary(detail.getSummary());
//            t.setCreateTime(detail.getCreateTime());
//            t.setViewnum(detail.getViewnum());
//            t.setFavornum(detail.getFavornum());
//            t.setReplynum(detail.getReplynum());
//            t.setThumbsupnum(detail.getThumbsupnum());
//
//            t.setCoverUrl(detail.getCoverUrl());
//            //List<String> list = strategyTagService.getTagsBySDetailId(detail.getId());
//            //t.setTags(list);
//
//            Destination dest = destinationService.getCountry(detail.getDest().getId());
//            t.setCountryId(dest.getId());
//            t.setCountryName(dest.getName());
//            dest = destinationService.getProvince(detail.getDest().getId());
//            if (dest != null) {
//                t.setProvinceId(dest.getId());
//                t.setProvinceName(dest.getName());
//            }
//            strategyTemplateSearchService.saveOrUpdate(t);
//        }
        List<Travel> ts = travelService.list();

        for (Travel travel : ts) {
            TravelTemplate tt = new TravelTemplate();
            tt.setId(travel.getId());
            tt.setAuthorId(travel.getAuthor().getId());
            tt.setAuthorName(travel.getAuthor().getNickname());
            tt.setCoverUrl(travel.getCoverUrl());
            tt.setCreateTime(travel.getCreateTime());
            tt.setDestId(travel.getDest().getId());
            tt.setDestName(travel.getDest().getName());
            tt.setReplynum(travel.getReplynum());
            tt.setSummary(travel.getSummary());
            tt.setTitle(travel.getTitle());
            tt.setViewnum(travel.getViewnum());
            travelTemplateSearchService.saveOrUpdate(tt);
        }
        List<Destination> ds = destinationService.list();

        for (Destination d : ds) {

            DestinationTemplate tt = new DestinationTemplate();

            tt.setId(d.getId());
            tt.setCoverUrl(d.getCoverUrl());
            tt.setName(d.getName());
            tt.setInfo(d.getInfo());
            destinationTemplateSearchService.saveOrUpdate(tt);
        }
        return "ok";
    }
}
